<?php 
/**
*file LoginModel.class.php
*用户登录类
*
*@auther houtizong
*@version 1.0
*/
defined('ACC') ||exit ('ACC Denied');

class LoginModel extends Model{
	protected $table = 'user'; 
	protected $pk = 'user_id'; //主键

    //表中的所有字段 跟$_POST过来的字段匹配
	protected $_field = array(
		'user_id','username','nick','password','email','regtime','lastlogin'
		);
		
	//自动填充
	protected $_auto = array(
            array('lastlogin','function','time')
		);
   //验证
    protected $_valid = array(
            array('username',1,'用户名不能为空','require'),
            array('username',0,'用户名必须在4-16字符之间','length','4,16'),
            array('password',1,'密码不能为空','require')
       );


/**
*根据username 查询一行用户信息
*@param string $username
*return array
*/
public function getUserRow($username){
	$sql = 'select user_id,username,email,nick from '.$this->table.' where username="'.$username.'"';
	return $this->db->getRow($sql);
}

/**
*更新用户最后一次登录时间
*@param $username   登录用户名
*@param $lastlogin  自动填充的lastlogin time()
*return 影响行数
*/
public function lastLogin($username,$lastlogin){
	$sql = 'update '.$this->table.' set '.' lastlogin= '.$lastlogin.' where username="'.$username.'"';
	if($this->db->query($sql)){
		return $this->db->affected_row();
	}else {
		return false;
	}
}






}
?>